package com.corona.game;

import com.corona.Game;

import java.util.Locale;

/* compiled from: Battle.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/CheckMovesLearned.class */
class CheckMovesLearned extends Action {
    Pokemon pokemon;

    public CheckMovesLearned(Pokemon pokemon, Action nextAction) {
        super(new Object[0]);
        this.pokemon = pokemon;
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        Action action = new Action(new Object[0]);
        if (this.pokemon.learnSet.containsKey(Integer.valueOf(this.pokemon.level))) {
            String[] strArr = this.pokemon.learnSet.get(Integer.valueOf(this.pokemon.level));
            for (String attack : strArr) {
                if (Pokemon.attacksImplemented.contains(attack.toLowerCase(Locale.ROOT))) {
                    boolean alreadyLearned = false;
                    int i = 0;
                    while (true) {
                        if (i >= 4) {
                            break;
                        }
                        if (this.pokemon.attacks[i] != null && this.pokemon.attacks[i].equals(attack)) {
                            alreadyLearned = true;
                            break;
                        }
                        i++;
                    }
                    if (!alreadyLearned) {
                        int i2 = 0;
                        while (true) {
                            if (i2 >= 4) {
                                break;
                            } else if (this.pokemon.attacks[i2] == null) {
                                action.append(new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, this.pokemon.nickname.toUpperCase(Locale.ROOT) + " learned " + attack.toUpperCase(Locale.ROOT) + "!", "fanfare1.ogg", true, true, (Action) null))));
                                this.pokemon.attacks[i2] = attack;
                                if (game.type == Game.Type.CLIENT) {
                                    game.client.sendTCP(new Network.LearnMove(game.player.network.id, 0, i2, attack));
                                }
                                alreadyLearned = true;
                            } else {
                                i2++;
                            }
                        }
                        if (!alreadyLearned) {
                            action.append(new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, this.pokemon.nickname.toUpperCase(Locale.ROOT) + " is trying to learn " + attack.toUpperCase(Locale.ROOT) + ".", (String) null, (Action) null, new DisplayText(game, "Which move should be forgotten?", (String) null, true, true, (Action) new DrawAttacksMenu(attack, this.pokemon, null))))));
                        }
                    }
                }
            }
        }
        action.append(this.nextAction);
        game.actionStack.remove(this);
        game.insertAction(action);
    }
}
